/* ajax标记的显示 */
$().ready(function(){
	//设置ajax配置
	$.ajaxSetup({
		type:'post',
		async: false
	});
	//设置ajax的等待
	var _img='/extend/pic/loading.gif';
	var _height=$(window).height()+'px';
	var _width=$(window).width()+'px';
	var _html='<div id="ajax_flag" style="display:none;position:absolute;z-index:1000000;"><div id="back_div" style="background:#666666 url(/extend/pic/loading_back.png) repeat scroll 50% 50%;opacity:0.5;opacity:.30;filter:Alpha(Opacity=30);position:absolute"></div><div id="loading_div" style="position:absolute;"><img src="'+_img+'"></div></div>';
	$(document.body.firstChild).before(_html);
	$('#ajax_flag').ajaxStart(function(){
		var top = (document.documentElement.scrollTop);
		top = top+'px';
		$(this).css('top',top);
		$('#back_div').css('height',_height);
		$('#back_div').css('width',_width);
　　 $(this).show();
　　 fnDivcenter('loading_div');
	})
	$("#ajax_flag").ajaxError(function(){
　　 $(this).show();
	});
	$('#ajax_flag').ajaxStop(function(){
		$(this).hide();
	})
})


/* 去除空格 */
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/* 用于input标签输入数据时检查，强制性转祛除非法字符    \ / : * ? " < > | & % '~  */
function fnInputFilterFCC(obj){   
	var reg = /[\\\/\*\?"<>|&%'`~]/g;
	obj.value = obj.value.replace(reg,"");   
}
/* 用于input标签输入数据时检查，只能是数字 */
function fnInputFilterFCCN(obj){   
	var reg = /[\D]/g;
	obj.value = obj.value.replace(reg,"");   
}
/*输入非中文字符*/
function fchinese(obj){
	var reg = /[\u4e00-\u9fa5]/g;
	obj.value = obj.value.replace(reg,"");  
}
/* 去除空格 */
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
/* 设置DIV居中 */
function fnDivcenter(id){   
	/*var divId=document.getElementById(id);
	divId.style.left=(document.body.clientWidth-divId.clientWidth)/2+document.body.scrollLeft;   
	divId.style.top=(document.body.clientHeight-divId.clientHeight)/2+document.body.scrollTop; */  
	var _height=$(window).height();
	var _width=$(window).width();
	var div_height=document.getElementById(id).scrollHeight;
	var div_width=document.getElementById(id).scrollWidth;
	var _top=(_height-div_height)/2+document.body.scrollTop;
	var _left=(_width-div_width)/2+document.body.scrollLeft;
	$('#'+id).css('left',_left);
	$('#'+id).css('top',_top);
}
/* 打开一个窗体默认的参数,主要是窗体居中用 */
function winArgs(){
	var width=800;
	var height=400;
	if(arguments[0]) width = arguments[0];
	if(arguments[1]) height = arguments[1];
	return 'width='+width+',height='+height+',resizable=1,scrollbars=1,left='+(screen.width-width)/2+',top='+(screen.height-height)/2;
}
//弹出式DIV
function show_div(args){
	var times=+new Date();
	var R = {
		background_id:'background_div_'+times,
		div_id:'inner_div_'+times,
		title_id:'title_div_'+times, 
		backgroundcolor:'#999999',
		frames_name:'msg_frame'+times,
		width:400,
		height:300,
		html:'',
		title:'站内信管理',
		func:function(){},
		title_height:20
	};
	jQuery.extend(R,args);
	show_div_R = jQuery.extend({},R);
	var _left=document.body.offsetWidth/2-R.width/2;
	div_height=screen.height>document.body.offsetHeight?screen.height:document.body.offsetHeight;
	var htmls='<div style="position:absolute;top:0px;left:0px;width:'+screen.width+'px;height:'+screen.height+'px;z-index:49999;background-color:gray;opacity:0.75;filter:Alpha(Opacity=75);" id="'+R.background_id+'"></div>';
	htmls+='<div style="position:absolute;top:80px;left:'+_left+'px;width:'+R.width+'px;height:'+R.height+'px;background-color:#FBFBFA;border:3px #525252 solid;z-index:50000" id="'+R.div_id+'"><div id="'+R.title_id+'" style="background-color:#E2EAF8;height:20px;padding:8px;cursor:move;color:#1A6DC1;margin-bottom:5px" >'+R.title+'<input type="text" id="show_div_temp" style="display:none"/><div style=" position:absolute;top:8px;right:8px;cursor:pointer;" id="remove_img">Close</div></div><div id="iframe_div">'+R.html+'</div></div>';
	$('select').hide();
	$(document.body.firstChild).before(htmls);
	if ($.browser.msie) {window.parent.frames[R.frames_name].location.reload(); }
	
 	$('#'+R.title_id).mousedown(function (event){ 
			$('#'+R.div_id).css('opacity','0.75'); 
			$('#'+R.div_id).css('filter','Alpha(Opacity=75)'); 
			var x=event.clientX+document.body.scrollLeft;
			var y=event.clientY+document.body.scrollTop;
			var old_top=parseInt($('#'+R.div_id).css('left'));
			var old_left=parseInt($('#'+R.div_id).css('top'));
			var DragStart = function (e){
					new_left=old_top+parseInt(e.clientX)-x+'px';
					new_top=old_left+parseInt(e.clientY)-y+'px';
					$('#'+R.div_id).css('left',new_left);
					$('#'+R.div_id).css('top',new_top);
			};
			var DragEnd = function(){
				$('#'+R.div_id).css('opacity','1'); 
				$('#'+R.div_id).css('filter','Alpha(Opacity=100)');
				$(document).unbind('mousemove',DragStart);
				$(document).unbind('mouseup',DragEnd); 
			} 
			$(document).mousemove(DragStart);
			$(document).mouseup(DragEnd);
	});
	removeIt = function(e){
		R.func(e);
	    $('select').show();
		$('#'+R.div_id).remove();
 		$('#'+R.background_id).remove();
	}; 
	$('#remove_img').click(removeIt);
}
//添加到收藏夹
function AddFavorite(sURL, sTitle){
	try{
			window.external.addFavorite(sURL, sTitle);
		}catch (e){
			try{
				window.sidebar.addPanel(sTitle, sURL, "");
			}catch (e){
				alert("加入收藏失败，请使用Ctrl+D进行添加");
			}
	}
}
//设为首页
//e.g:SetHome(this,window.location)
function SetHome(obj,vrl){
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}catch(e){
		if(window.netscape) {
			try{
	      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
}